package com.ww.learn.oop.extend

open class Base(val name: String) {
    init {
        println("base init...")
    }

    open val size: Int =
        name.length.also { println("base init size: $it") }
}

class Derived(
    name: String,
    val lastName: String,
) : Base(name.replaceFirstChar { it.uppercaseChar() }.also { println("call Base($it)") }) {
    init {
        println("Derived init...")
    }

    override val size: Int =
        (super.size + lastName.length).also { println("derived init size: $it") }
}

// 打印结果
//call Base(Hello)
//base init...
//base init size: 5
//Derived init...
//derived init size: 10
fun main() {
    Derived("hello", "world")
}